<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>ES9-命名捕获</title>
    <script>
        let str = '2018-03-20';

        let reg = /(\d{4})-(\d{2})-(\d{2})/;

        // console.log(str.match(reg));
        let dateArr = str.match(reg);

        let year = dateArr[1];
        let month = dateArr[2];
        let day = dateArr[3];

        console.log(year, month, day);
    </script>
    <script>
        let str2 = '2019-04-21';
        //es9 
        let reg2 = /(?<year1>\d{4})-(?<month1>\d{2})-(?<day1>\d{2})/;

        // console.log(str2.match(reg2).groups);

        let {
            year1,
            month1,
            day1
        } = str2.match(reg2).groups;
        console.log(year1, month1, day1);
    </script>
</head>

<body>

</body>

</html>